<template>
  <div id="app">
    <el-dialog
      title="密码验证"
      :visible.sync="$store.state.showPassword"
      width="30%"
      :before-close="handleClose"
    >
      <span>请输入密码</span>
      <el-input v-model="password" style="margin-top: 20px"> </el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="$store.state.showPassword = false">取 消</el-button>
        <el-button type="primary" @click="checkPassword">确 定</el-button>
      </span>
    </el-dialog>

    <router-view :key="$route.fullPath"></router-view>
  </div>
</template>

<script>
import eventBus from "../src/util/myEventBus";
import request from "../src/axios/request";
export default {
  data() {
    return {
      password: null,
    };
  },
  mounted() {},
  beforeDestroy() {},
  methods: {
    async checkPassword() {
      let res = await request({
        url: "/user/api/checkPassword",
        method: "POST",
        data: {
          password: this.password,
        },
      });
      if (res.data.status == 200) {
        this.password=null
        this.$store.state.showPassword = false;
        console.log("重新发送请求");
        this.$store.state.checkedPassword = "true";
        this.$nextTick(() => {
          eventBus.$emit(this.$store.state.lastMethod,this.$store.state.lastData);
        });
      }
    },
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
}

nav a.router-link-exact-active {
  color: #42b983;
}
</style>
